import historyEchart from "../../workWx/customer-radar/components/historyEchart.vue";
import portEchart from "../../workWx/customer-radar/components/portEchart.vue";
import pageRanking from "../../workWx/customer-radar/components/pageRanking.vue";
import trackList from "./components/trackList.vue"
import pageRankList from "./components/pageRank.vue"
import Visitorlist from "./components/Visitorlist.vue"
import { scrollMixin } from "utils/mixin";
export default {
  mixins: [scrollMixin], //加载更多
  data() {
    return {
      isShowCalendar: false,
      currentTime: new Date(),
      timeText: "",
      markDate: [],
      display_set: [],
      top_list: [],
      resData: null,
      cumulative: {},
      history: [],
      port: [],
      rank: [],
      member: [],
      visit_data: [],
      tabInd: 1,
      maxDate: new Date(),
      currentDate: new Date(),

      //more
      isLoadMore: true,
      page: 1,
      total_page: 0
    }
  },
  activated() {
    let date = this.fun.getKey("date");
    if (date) {
      this.currentTime = new Date(date);
    }
    this.timeText = this.fun.dateFormat("YYY-mm-dd", this.currentTime);
    this.markDate[0] = this.fun.dateFormat("YYYY/mm/dd", this.currentTime);
    this.getData();
    this.getList();
    window.scrollTo({
      top: 0,
      left: 0,
      behavior: "smooth"
    });
  },
  computed: {

  },
  methods: {
    onClickLeft() {
      try {
        this.$router.go(-1)
      } catch (error) {
        this.$router.push(this.fun.getUrl('home'));
      }
    },
    selectTab(key) {
      this.tabInd = key;
      this.init();
      this.getList();
    },
    init() {
      this.page = 1;
      this.total_page = 0;
      this.isLoadMore = true;
      this.top_list = [];
    },
    showCalendar() {
      this.isShowCalendar = true;
    },
    cancel() {
      this.isShowCalendar = false;
    },
    confirm(e) {
      this.timeText = this.fun.dateFormat("YYY-mm-dd", e)
      this.isShowCalendar = false;
      this.init();
      this.getData();
      this.getList();
    },
    // changeDate(day) {
    //   this.markDate = [day];
    //   this.currentTime = new Date(day);
    //   this.timeText = this.fun.dateFormat("YYY-mm-dd", this.currentTime);
    //   this.isShowCalendar = false;
    //   this.getStatisticsByDay();
    // },
    getData() {
      let json = {};
      json.level_type = this.$route.params.is_type;
      json.date = this.timeText;
      $http
        .get(
          "plugin.customer-center.frontend.controllers.browse.index", json,
          "加载中"
        )
        .then(response => {
          if (response.result === 1) {
            console.log(response)
            this.history = response.data.history_data;
            this.port = response.data.port_data;
            this.visit_data = response.data.visit_data;
            this.display_set = response.data.display_set;
          } else {
            this.$dialog.alert({ message: response.msg });
          }
        })
        .catch(error => {
          console.log(error);
        });
    },
    getList() {
      let json = {};
      json.level_type = this.$route.params.is_type;
      json.date = this.timeText;
      json.top_type = this.tabInd;
      $http
        .get(
          "plugin.customer-center.frontend.controllers.browse.get-record-list",
          json,
          "加载中"
        )
        .then(response => {
          if (response.result === 1) {
            this.isLoadMore = true;
            this.total_page = response.data.top_list.last_page;
            if (!this.total_page) {
              this.total_page = 0;
            }
            this.top_list = response.data.top_list.data;
            console.log(this.top_list)
          } else {
            this.$dialog.alert({ message: response.msg });
          }
        })
        .catch(error => {
          console.log(error);
        });
    },
    getMoreData() {
      this.isLoadMore = false; // 防止多次请求分页数据
      if (this.page >= this.total_page) {
        return;
      } else {
        let json = {};
        json.level_type = this.$route.params.is_type;
        json.date = this.timeText;
        json.top_type = this.tabInd;
        this.page = this.page + 1;
        json.page = this.page;
        $http.post("plugin.customer-center.frontend.controllers.browse.get-record-list", json, "加载中").then(
          response => {
            this.isLoadMore = true;
            if (response.result === 1) {
              var myData = response.data.top_list.data;
              this.top_list = this.top_list.concat(myData); //数组拼接
            } else {
              this.page = this.page - 1;
              this.isLoadMore = false;
            }
          },
          function (response) {
            console.log("response", response);
            // error callback
          }
        );
      }
    },
  },
  components: {
    historyEchart,
    portEchart,
    pageRanking,
    trackList,
    pageRankList,
    Visitorlist
  }
}